#include "drivers/REGX52.H"
#include "Delay.H"
#include "Nixie.H"
#include "LCD1602.H"
#include "MatrixKey.h"

//  

unsigned char KeyNum;
unsigned int password,count;

void main() {


    LCD_Init();
    LCD_ShowString(1,1,"password:");

//    LCD_ShowNum(1);
    while (1) {

        KeyNum = MaxtrixKey();
        if(KeyNum) {
            if(KeyNum<=10) {
                if(count<4) {
                    password *= 10;  // 密码左移一位
                    password += KeyNum % 10;
                    count++;
                }
                LCD_ShowNum(2,1,password,4);
            }
            if(KeyNum == 11) {
                if(password == 2345) {
                    LCD_ShowString(1,14,"ok ");
                    password=0;
                    count=0;
                    LCD_ShowNum(2,1,password,4);
                } else{
                    LCD_ShowString(1,14,"ERR");
                    password=0;
                    count=0;
                    LCD_ShowNum(2,1,password,4);
                }
            }
            if(KeyNum==12) {
                password=0;
                count=0;
                LCD_ShowNum(2,1,password,4);
            }
        }
    }
}

